﻿using System.Linq;

namespace Eugenhome.Atrium.Mail.Web
{
    /// <summary>
    /// 
    /// </summary>
    public class MailItem
    {
        /// <summary></summary>
        private GadagetMessage _gadagetMessage;

        /// <summary></summary>
        public string ID { get { return _gadagetMessage.ID.ToString(); } }

        ///// <summary></summary>
        //public string MessageHref { get { return "https://mail.google.com/mail/u/0/?account_id=eugen.dolgi%40gmail.com#inbox/" + _gadagetMessage.ID; } }

        /// <summary></summary>
        public string MessageCaption
        {
            get
            {
                string childs = _gadagetMessage.Childs.Count.Equals(0) ? "" : " (" + (_gadagetMessage.Childs.SelectMany(item => item.Refs).Distinct().Count()+2).ToString() + ")";
                string format = (_gadagetMessage.IsNew ? "<b>{0}" + childs + "</b>" : "{0}" + childs) + " - {1}";

                return string.Format(format, _gadagetMessage.FromName, _gadagetMessage.Subj);
            }
        }

        /// <summary></summary>
        public string OpenLink { get { return _gadagetMessage.OpenLink; } }

        /// <summary></summary>
        public string Method { get { return _gadagetMessage.Method; } }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="gadagetMessage"></param>
        public MailItem(GadagetMessage gadagetMessage)
        {
            _gadagetMessage = gadagetMessage;
        }
    }
}